<%-- 
    Document   : agregar_menu
    Created on : Feb 18, 2013, 3:19:46 PM
    Author     : john
--%>

<%@page import="acceso.util.UserSesion"%>
<%@page import="javax.xml.xpath.XPathConstants"%>
<%@page import="javax.xml.xpath.XPathExpression"%>
<%@page import="javax.xml.xpath.XPathFactory"%>
<%@page import="javax.xml.xpath.XPath"%>
<%@page import="org.w3c.dom.Node"%>
<%@page import="sun.font.EAttribute"%>
<%@page import="acceso.util.Escritor"%>
<%@page import="org.w3c.dom.NamedNodeMap"%>
<%@page import="org.w3c.dom.NodeList"%>
<%@page import="java.util.List"%>
<%@page import="acceso.login.MenuUtil"%>
<%@page import="org.w3c.dom.Element"%>
<%@page import="org.w3c.dom.Document"%>
<%@page contentType="text/html" pageEncoding="ISO-8859-1"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>

<%
    String url = request.getAttribute("url") + "";
    String titulo_menu = "";
    String id_padre = "";
    List menus = null;

    try {
//        Document doc = ((Sesion) request.getSession().getAttribute("sesion")).getDoc_menu();
        Document doc = ((UserSesion) request.getSession().getAttribute("US")).getDoc_menu();

        if (request.getParameter("menu_id") != "" && request.getParameter("menu_id") != null) {
            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();

            Element result = (Element) xpath.evaluate("//menu[@id=" + request.getParameter("menu_id") + "]", doc, XPathConstants.NODE);
            titulo_menu = result.getAttributes().getNamedItem("titulo").getNodeValue();
            menus = MenuUtil.getFirstChilds(result);

            if (result.getParentNode().getNodeName() == "mmenu") {
                id_padre = "mmenu";
            } else {
                id_padre = result.getParentNode().getAttributes().getNamedItem("id").getNodeValue();
            }
        } else {
            Element menu = doc.getDocumentElement();
            menus = MenuUtil.getFirstChilds(menu);
            titulo_menu = "Menu principal";
        }
    } catch (Exception ex) {
        Escritor.escribe_errors("Error menu_movil: " + ex);
    }

    request.setAttribute("titulo_menu", titulo_menu);
    request.setAttribute("menus", menus);
    request.setAttribute("id_padre", id_padre);

%>

<html>
    <head>
        <title>${sessionScope[param.id_frawor].no_contit }</title>
        <link rel="shortcut icon" href="../favicon.ico">
        <meta name="viewport" content="initial-scale=1.0, user-scalable=yes">

        <link rel="stylesheet" type="text/css" media="all" href="../css/movil/wfm.css?a" />

        <style>
            body{
                /*background-color: #F1F1F1;*/
            }
            .li_primero{
                /*background-color: white;*/
                background-color: #2C79B3;
                /*border-bottom: 1px solid #CCCCCC;*/
                border-bottom: 1px solid #2B6484;
                color:#ffffff;
                font-family: Arial,Verdana,Tahoma,Ms Sans Serif,Sans-Serif,Helvetica;
            }
            .li_lista{
                /*background-color: white;*/
                /*background-color: #2B6484;*/
                background-color: #2C79B3;
                /*border-bottom: 1px solid #CCCCCC;*/
                border-bottom: 1px solid #2B6484;
                border-top: 0px;
                color:#ffffff;
                font-family: Arial,Verdana,Tahoma,Ms Sans Serif,Sans-Serif,Helvetica;
            }
        </style>
        <script>
            function gopro(uri) {
                top.gopro(uri);
            }
        </script>
    </head>
    <body>
        <div id="mw-mf-page-left" style="margin:0px;width: 100%;">
            <div id="mw-mf-content-left">
                <ul id="mw-mf-menu-main">
                    <c:if test="${id_padre != ''}">
                        <li class="li_primero">
                            <a title="Atras" style="padding-left: 32px" id="randomButton" class="link_li" href="<%=request.getRequestURL()%>?id_frawor=${param.id_frawor}&menu_id=${(id_padre=='mmenu')?'':id_padre}">
                                <div class="mobile_icon_left" style="display: inline-block;">
                                </div>
                                Atras
                            </a>
                        </li>
                    </c:if>
                    <c:forEach items="${menus}" var="m" varStatus="ix">
                        <%--<li class="${(ix.count == '1')?'li_primero':'li_lista'}">--%>
                        <li class="li_lista">
                            <c:choose>
                                <c:when test="${fn:contains(m['class'].name, 'Item')}">
                                    <a href="#" onclick="gopro('${m.url}')" title="${m.descripcion}" class="link_li">
                                        ${m.descripcion}
                                    </a>
                                </c:when>
                                <c:otherwise>
                                    <a href="<%=request.getRequestURL()%>?id_frawor=${param.id_frawor}&menu_id=${m.id}" title="${m.descripcion}" class="link_li_2" >
                                        ${m.descripcion} 
                                        <div class="mobile_icon_right" style="display: inline-block;">
                                        </div>
                                    </a>
                                </c:otherwise>
                            </c:choose>
                        </li>
                    </c:forEach>
                </ul>
            </div>
        </div>
    </body>
</html>
                                            <!--<center><img src="${pageContext.request.contextPath}/img/movil/expandir.png" style="vertical-align: middle"></center>-->
<!--                                        <div style="display: inline-block; width: 32px">
                                            <center><img src="${pageContext.request.contextPath}/img/movil/expandir.png" style="vertical-align: middle"></center>
                                        </div>-->